package com.ocr.camera;

import java.io.File;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
import com.ocr.client.Client;
import com.ocr.client.PyClient;
import com.ocr.utils.Constains;
import com.ocr.utils.DialogUtils;
import com.ocr.utils.StoreSetting;
import com.ocr.utils.Utils;
import com.ocr.view.GraphicView;

public class OCRCameraActivity extends Activity implements OnClickListener {

	public static String TAG = "OCRCameraActivity";

	public static int DEFAULT_CURRENT_OCR_LANGUAGE = 0;
	public static int DEFAULT_CURRENT_TRANS_LANGUAGE = 1;
	public static String DEFAULT_OCR_LANGUAGE = "ENGLISH";
	public static String DEFAULT_TRANSLATE_LANGUAGE = "JAPANESE";

	CameraPreview preview;
	FrameLayout frame;

	ImageButton searchButton;
	ImageButton shareButton;
	LinearLayout searchChoiceLayout;
	LinearLayout shareChoiceLayout;

	ImageButton facebookButton;
	ImageButton twitterButton;
	ImageButton googleButton;
	ImageButton wikiButton;

	// ImageButton zoominButton;
	// ImageButton zoomoutButton;
	// ImageButton autoButton;
	ImageButton takeButton;

	TextView ocrLangTextView;
	TextView transLangTextView;

	LinearLayout langchoiceLayout;
	Button okLangChoice;

	ListView ocrlangListView;
	ListView translangListView;

	GraphicView graphicview;

	TextView translatedTextview;
	TextView ocrTextview;
	LinearLayout ocrResultLayout;
	LinearLayout translatedResultLayout;

	ImageView recogImageview;

	ImageButton camerazoominButton;
	ImageButton camerazoomoutButton;

	ImageButton switchResult;

	int currentOCRLang = DEFAULT_CURRENT_OCR_LANGUAGE;
	int currentTransLang = DEFAULT_CURRENT_TRANS_LANGUAGE;

	ProgressDialog doOcrDialog;
	ProgressDialog doTranslateDialog;

	Bitmap currentPicture = null;
	Bitmap recogPicture = null;

	String originString = "japan";
	String translatedString = "japan";

	boolean translatedTextviewShow = true;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		// get view

		searchButton = (ImageButton) findViewById(R.id.search);
		shareButton = (ImageButton) findViewById(R.id.share);
		searchChoiceLayout = (LinearLayout) findViewById(R.id.search_choice);
		shareChoiceLayout = (LinearLayout) findViewById(R.id.share_choice);

		facebookButton = (ImageButton) findViewById(R.id.facebook);
		twitterButton = (ImageButton) findViewById(R.id.twitter);
		googleButton = (ImageButton) findViewById(R.id.google);
		wikiButton = (ImageButton) findViewById(R.id.wikipedia);

		// zoominButton = (ImageButton) findViewById(R.id.zoomin);
		// zoomoutButton = (ImageButton) findViewById(R.id.zoomout);
		// autoButton = (ImageButton) findViewById(R.id.auto);
		takeButton = (ImageButton) findViewById(R.id.take);

		ocrLangTextView = (TextView) findViewById(R.id.origin_language);
		transLangTextView = (TextView) findViewById(R.id.to_language);

		langchoiceLayout = (LinearLayout) findViewById(R.id.langchoice);
		okLangChoice = (Button) findViewById(R.id.ok);

		ocrlangListView = (ListView) findViewById(R.id.ocrlang);
		translangListView = (ListView) findViewById(R.id.translang);

		graphicview = (GraphicView) findViewById(R.id.supervisor);

		translatedTextview = (TextView) findViewById(R.id.translated);
		ocrTextview = (TextView) findViewById(R.id.OCRtext);

		recogImageview = (ImageView) findViewById(R.id.recog_imageview);

		camerazoominButton = (ImageButton) findViewById(R.id.camerazoomin);
		camerazoomoutButton = (ImageButton) findViewById(R.id.camerazoomout);

		switchResult = (ImageButton) findViewById(R.id.switch_result);
		ocrResultLayout = (LinearLayout) findViewById(R.id.ocrresultlayout);
		translatedResultLayout = (LinearLayout) findViewById(R.id.translatedresultlayout);

		// add listener
		shareButton.setOnClickListener(onShareButtonClick);
		searchButton.setOnClickListener(onSearchButtonClick);

		facebookButton.setOnClickListener(onFacebookButtonClick);
		twitterButton.setOnClickListener(onTwitterButtonClick);
		wikiButton.setOnClickListener(onWikiButtonClick);
		googleButton.setOnClickListener(onGoogleButtonClick);

		// zoominButton.setOnClickListener(onZoominButtonClick);
		// zoomoutButton.setOnClickListener(onZoomOutButtonClick);
		// autoButton.setOnClickListener(onAutoButtonClick);
		takeButton.setOnClickListener(onTakeButtonClick);

		ocrLangTextView.setOnClickListener(onOcrLangTextViewClick);
		transLangTextView.setOnClickListener(onTransLangTextViewClick);

		okLangChoice.setOnClickListener(onOkLangChoiceClick);
		translatedTextview.setOnClickListener(onTranslatedTextViewClick);

		ocrlangListView.setOnItemClickListener(onOcrlangListItemClick);
		translangListView.setOnItemClickListener(onTranslangListItemClick);

		camerazoominButton.setOnClickListener(onCamerazoominButtonClick);
		camerazoomoutButton.setOnClickListener(onCamerazoomoutButtonClick);

		switchResult.setOnClickListener(onSwitchResultButtonClick);

		ocrLangListData();
		transLangListData();

		// start using camera
		if (Utils.checkCameraHardware(this)) {
			frame = (FrameLayout) findViewById(R.id.preview);
			// LayoutParams params = frame.getLayoutParams();
			// Log.i("Frame Size", params.width+" "+params.height);
			preview = new CameraPreview(this);
			frame.addView(preview);

		} else {

			DialogUtils.messageDialog(this, "Warning ...",
					"No camera in this device");
		}

		// initial view
		hiddenSearchChoice();
		hiddenShareChoice();
		hiddenLangChoiceLayout();
		initialResultTextview();

	}

	/**
	 * release camera
	 */
	public void releaseCamera() {
		/*
		 * if (camera != null) { camera.stopPreview(); camera.release(); camera
		 * = null; }
		 */
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		// Handle item selection
		switch (item.getItemId()) {
		case R.id.help:

			return true;
		case R.id.setting:
			Intent intent = new Intent(OCRCameraActivity.this, Settings.class);
			startActivity(intent);
			return true;
		case R.id.about:
			
			return true;
		case R.id.translate:
			Intent trans = new Intent(OCRCameraActivity.this, TranslateAc.class);
			Bundle bun = new Bundle();
			if(originString == null)
				originString ="";
			bun.putString("text",originString);
			trans.putExtras(bun);
			startActivity(trans);
			
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Log.i("ON PAUSE", "PAUSED");
		// releaseCamera();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Log.i("ON RESUME", "RESUMED");
		// camera = getCameraInstance();
		// preview.setCamera(camera);

	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		releaseCamera();
	}

	/**
	 * translate
	 * 
	 * @param text
	 * @param fromlang
	 * @param tolang
	 * @return
	 */
	public void doTranslate(final String text, final String fromlang,
			final String tolang) {

		if (Utils.checkInternetConnection(this)) {

			doTranslateDialog = ProgressDialog.show(this, "Translating",
					"Please, wait for few minute.....");

			new Thread() {
				public void run() {
					String translatedText = null;

					// translator translator = new Translator();
					// translatedText = translator.translate(text,
					// Language.valueOf(fromlang.toUpperCase()),
					// Language.valueOf(tolang.toUpperCase()));

					Translate.setKey(Constains.BING_TRANSLATE_API_KEY);

					try {
						translatedText = Translate.execute(text,
								Language.valueOf(fromlang.toUpperCase()),
								Language.valueOf(tolang.toUpperCase()));

						Message message = new Message();
						Bundle bundle = new Bundle();
						bundle.putString("character", translatedText);
						message.setData(bundle);
						doTranslateHandler.sendMessage(message);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

				};
			}.start();
		} else {

			DialogUtils.messageDialog(this, "Warning ...",
					"No internet connection");

		}
	}

	/**
	 * character recognition
	 * 
	 * @param language
	 * @param picture
	 */
	public void doOCR(final String language, final Bitmap picture) {
		// show progress dialog
		if (Utils.checkInternetConnection(this)) {
			doOcrDialog = ProgressDialog.show(this, "Recognizing",
					".Please, wait for few minute.....");

			// character recognition thread
			new Thread() {
				public void run() {

					String character = null;

					File file = Utils.savePicture(picture);
					Client client = new Client(file, language);
					if (client != null) {
						character = client.doOCR();
					}

					// handler send message
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putString("character", character);
					message.setData(bundle);
					doOcrHandler.sendMessage(message);

				}

			}.start();
		} else {

			DialogUtils.messageDialog(this, "Warning ...",
					"No internet connection");

		}
	}

	public void doPyOCR(final String language, final Bitmap picture) {
		if (Utils.checkInternetConnection(this)) {
			doOcrDialog = ProgressDialog.show(this, "Recognizing",
					".Please, wait for few minute.....");

			// character recognition thread
			new Thread() {
				public void run() {

					String character = null;

					try {
						character = PyClient.OCRClient(picture, language);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						character = "OCR Error";
					}
					// handler send message
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putString("character", character);
					message.setData(bundle);
					doOcrHandler.sendMessage(message);

				}

			}.start();
		} else {

			DialogUtils.messageDialog(this, "Warning ...",
					"No internet connection");

		}
	}

	/**
	 * wikipedia search
	 */
	static String wikiURL_JP = "http://jp.m.wikipedia.org/wiki?search=";
	static String wikiURL_VIE = "http://vi.m.wikipedia.org/wiki?search=";
	static String wikiURL_ENG = "http://en.m.wikipedia.org/wiki?search=";

	public String getWikiURL() {
		String lang = StoreSetting.restoreLangSetting(this);
		if (lang == null || lang.equals("ENGLISH")) {
			return wikiURL_ENG;
		} else if (lang.equals("VIETNAMESE")) {
			return wikiURL_VIE;
		} else if (lang.equals("JAPANESE")) {
			return wikiURL_JP;
		}
		return null;
	}

	public void wikipediaSearch(String keyword) {
		// TODO Auto-generated constructor stub

		String url = getWikiURL();
		if (url != null) {
			Uri uri = Uri.parse(url + keyword);
			Log.i("URI", uri.toString());
			Intent intent = new Intent(Intent.ACTION_VIEW).setData(uri);
			startActivity(intent);
		}
	}

	/**
	 * web search
	 * 
	 * @param keyword
	 */
	static String google_jp = "http://www.google.co.jp/m/search?site=images&q=";
	static String google_vie = "http://www.google.com.vn/m/search?site=images&q=";
	static String google_eng = "http://www.google.com/m/search?site=images&q=";

	public String getGoogleURL() {
		String lang = StoreSetting.restoreLangSetting(this);
		if (lang == null || lang.equals("ENGLISH")) {
			return google_eng;
		} else if (lang.equals("VIETNAMESE")) {
			return google_vie;
		} else if (lang.equals("JAPANESE")) {
			return google_jp;
		}
		return null;
	}

	public void googleSearch(String keyword) {
		String url = getGoogleURL();
		if (url != null) {
			Uri uri = Uri.parse(url + keyword);
			Intent intent = new Intent(Intent.ACTION_VIEW).setData(uri);
			startActivity(intent);
		}
	}

	/**
	 * 
	 */
	public Bitmap cropPicture(Bitmap bitmap) {

		float recogx, recogy, recogwidth, recogheight;
		recogx = graphicview.getXOfTextBox() + graphicview.getLeft();
		recogy = graphicview.getYOfTextBox() + graphicview.getTop();
		recogwidth = graphicview.getWidthOfTextBox();
		recogheight = graphicview.getHeightOfTextBox();

		Log.i("recogx", String.valueOf(recogx));
		Log.i("recogy", String.valueOf(recogy));
		Log.i("recogwidth", String.valueOf(recogwidth));
		Log.i("recogheight", String.valueOf(recogheight));

		int picturewidth = bitmap.getWidth(), pictureheight = bitmap
				.getHeight();
		float scaleRateX = (float) picturewidth / preview.getWidth();
		float scaleRateY = (float) pictureheight / preview.getHeight();

		int realX = (int) (recogx * scaleRateX);
		int realY = (int) (recogy * scaleRateY);
		int realwidth = (int) (recogwidth * scaleRateX);
		int realheight = (int) (recogheight * scaleRateY);

		Log.i("rex", String.valueOf(realX));
		Log.i("rey", String.valueOf(realY));
		Log.i("rewidth", String.valueOf(realwidth));
		Log.i("reheight", String.valueOf(realheight));

		return Bitmap.createBitmap(bitmap, realX, realY, realwidth, realheight);
	}

	/**
	 * 
	 */
	public void initialResultTextview() {
		showTranslatedTextview();
		hiddenOCRTextview();
	}

	/**
	 * 
	 */
	public void hiddenTranslatedTextview() {
		LayoutParams params = translatedResultLayout.getLayoutParams();
		params.height = 0;
		translatedResultLayout.setLayoutParams(params);
	}

	/**
	 * 
	 */

	public void showTranslatedTextview() {
		LayoutParams params = translatedResultLayout.getLayoutParams();
		params.height = 120;
		translatedResultLayout.setLayoutParams(params);
	}

	/**
	 * 
	 */
	public void hiddenOCRTextview() {
		LayoutParams params = ocrResultLayout.getLayoutParams();
		params.height = 0;
		ocrResultLayout.setLayoutParams(params);
	}

	/**
	 * 
	 */
	public void showOCRTextview() {
		LayoutParams params = ocrResultLayout.getLayoutParams();
		params.height = 120;
		ocrResultLayout.setLayoutParams(params);
	}

	/**
	 * 
	 */
	public void hiddenLangChoiceLayout() {
		LayoutParams params = langchoiceLayout.getLayoutParams();
		params.height = 0;
		langchoiceLayout.setLayoutParams(params);
	}

	/**
	 * 
	 */
	public void showLangChoiceLayout() {
		LayoutParams params = langchoiceLayout.getLayoutParams();
		params.height = 420;
		langchoiceLayout.setLayoutParams(params);
	}

	/**
	 * 
	 */
	public void hiddenSearchChoice() {
		LayoutParams params = searchChoiceLayout.getLayoutParams();
		params.height = 0;
		searchChoiceLayout.setLayoutParams(params);
	}

	/**
	 * 
	 */
	public void showSearchChoice() {
		LayoutParams params = searchChoiceLayout.getLayoutParams();
		params.height = 60;
		searchChoiceLayout.setLayoutParams(params);
		wikiButton.setOnClickListener(onWikiButtonClick);
		googleButton.setOnClickListener(onGoogleButtonClick);
	}

	/**
	 * 
	 */
	public void hiddenShareChoice() {
		LayoutParams params = shareChoiceLayout.getLayoutParams();
		params.height = 0;
		shareChoiceLayout.setLayoutParams(params);
	}

	/**
	 * 
	 */
	public void showShareChoice() {
		LayoutParams params = shareChoiceLayout.getLayoutParams();
		params.height = 60;
		shareChoiceLayout.setLayoutParams(params);
	}

	public void hiddenCameraZoomBar() {
		if (!preview.camera.getParameters().isZoomSupported()) {
			LinearLayout zoombar = (LinearLayout) findViewById(R.id.camerazoombar);
			LayoutParams params = zoombar.getLayoutParams();
			params.height = 0;
			zoombar.setLayoutParams(params);
		}
	}

	public void ocrLangListData() {

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_single_choice,
				Constains.OCR_LANGUAGE);
		ocrlangListView.setAdapter(adapter);
		ocrlangListView.setItemsCanFocus(false);
		ocrlangListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		/*
		 * LangListAdapter adapter = new LangListAdapter(this,
		 * R.layout.language_list_item, Constains.OCR_LANGUAGE);
		 * ocrlangListView.setAdapter(adapter);
		 */
		// ocrlangListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

	}

	public void transLangListData() {
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_single_choice,
				Constains.TRANSLATE_LANGUAGE);
		translangListView.setAdapter(adapter);
		translangListView.setItemsCanFocus(false);
		translangListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		/*
		 * LangListAdapter adapter = new LangListAdapter(this,
		 * R.layout.language_list_item, Constains.TRANSLATE_LANGUAGE);
		 * translangListView.setAdapter(adapter);
		 */
		// translangListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

	}

	public void initialLangListView() {
		/*
		 * LangListItemView item = (LangListItemView) ocrlangListView
		 * .getChildAt(currentOCRLang); item.check.setChecked(true);
		 * 
		 * Log.i("Log", item.toString()); LangListAdapter adapter =
		 * (LangListAdapter) translangListView .getAdapter(); item =
		 * (LangListItemView) adapter.getView(currentTransLang, null, null); //
		 * item = (LangListItemView) translangListView //
		 * .getChildAt(currentTransLang); Log.i("Count",
		 * String.valueOf(translangListView.getChildCount()));
		 * item.check.setChecked(true);
		 */
		ocrlangListView.setItemChecked(currentOCRLang, true);
		translangListView.setItemChecked(currentTransLang, true);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
	}

	private Handler doTranslateHandler = new Handler() {
		public void handleMessage(Message msg) {

			doTranslateDialog.dismiss();
			Bundle data = msg.getData();
			translatedString = data.getString("character");
			if (translatedString == null)
				translatedTextview.setText("null");
			translatedTextview.setText(translatedString);
		};
	};

	private Handler doOcrHandler = new Handler() {

		public void handleMessage(Message msg) {
			doOcrDialog.dismiss();
			Bundle data = msg.getData();
			originString = data.getString("character");

			// xu ly ki tu nhan dang o day
			ocrTextview.setText(originString);

			if (originString != null && !originString.equals("")
					&& !originString.equals(Client.ERROR_RECOGNITION)) {
				doTranslate(originString, ocrLangTextView.getText().toString(),
						transLangTextView.getText().toString());
			}
		};
	};

	private Handler takepicturehandler = new Handler() {

		public void handleMessage(android.os.Message msg) {
			// Utils.saveImage(currentPicture);
			takeButton.setClickable(true);
			Log.i(TAG, "do OCR");
			doPyOCR(ocrLangTextView.getText().toString(), recogPicture);
			recogPicture = null;
			// doTranslate("test", ocrLangTextView.getText().toString(),
			// transLangTextView.getText().toString());
		};

	};

	/*
	 * test crop image public void dialogImageView(Bitmap bitmap){ final Dialog
	 * dialog = new Dialog(this);
	 * dialog.setContentView(R.layout.dialog_image_view);
	 * dialog.setTitle("This is my custom dialog box");
	 * dialog.setCancelable(true); //there are a lot of settings, for dialog,
	 * check them all out!
	 * 
	 * 
	 * //set up image view ImageView img = (ImageView)
	 * dialog.findViewById(R.id.image); img.setImageBitmap(bitmap);
	 * 
	 * //set up button Button button = (Button)
	 * dialog.findViewById(R.id.button); button.setOnClickListener(new
	 * OnClickListener() {
	 * 
	 * @Override public void onClick(View v) { dialog.dismiss(); } }); //now
	 * that the dialog is set up, it's time to show it dialog.show(); }
	 */
	private PictureCallback picturecallback = new PictureCallback() {

		@Override
		public void onPictureTaken(byte[] data, Camera camera) {
			// TODO Auto-generated method stub
			BitmapFactory.Options options = new BitmapFactory.Options();
			options.inSampleSize = 2;
			Bitmap currentPicture = BitmapFactory.decodeByteArray(data, 0,
					data.length, options);
			// Log.i("Size",
			// currentPicture.getWidth() + " "
			// + currentPicture.getHeight());
			recogPicture = cropPicture(currentPicture);
			currentPicture = null;
			recogImageview.setImageBitmap(recogPicture);
			// dialogImageView(recog_picture);
			// send message to handler
			takepicturehandler.sendEmptyMessage(0);
			// start preview
			camera.startPreview();
		}
	};

	private OnClickListener onShareButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			hiddenSearchChoice();
			showShareChoice();

		}
	};

	private OnClickListener onSearchButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			hiddenShareChoice();
			showSearchChoice();

		}
	};

	private OnClickListener onFacebookButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			hiddenShareChoice();
			// facebook click process in here
		}
	};
	private OnClickListener onTwitterButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			hiddenShareChoice();

		}
	};
	private OnClickListener onGoogleButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			hiddenSearchChoice();
			// google search
			googleSearch(originString);
		}
	};
	private OnClickListener onWikiButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			hiddenSearchChoice();
			// wikipedia search
			wikipediaSearch(translatedString);
		}
	};
	private OnClickListener onZoominButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			graphicview.increaseBoxSize();
			graphicview.invalidate();
			Log.i("zoomin", String.valueOf(graphicview.boxwidth));
		}
	};
	private OnClickListener onZoomOutButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			graphicview.decreaseBoxSize();
			graphicview.invalidate();
			Log.i("zoomout", String.valueOf(graphicview.boxwidth));
		}
	};
	/*
	 * private OnClickListener onAutoButtonClick = new OnClickListener() {
	 * 
	 * @Override public void onClick(View v) { // TODO Auto-generated method
	 * stub
	 * 
	 * } };
	 */
	private OnClickListener onTakeButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			takeButton.setClickable(false);
			preview.camera.takePicture(null, null, picturecallback);
		}
	};
	private OnClickListener onOcrLangTextViewClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			showLangChoiceLayout();
			initialLangListView();
		}
	};

	private OnClickListener onTransLangTextViewClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			showLangChoiceLayout();
			initialLangListView();
		}
	};

	private OnClickListener onOkLangChoiceClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			hiddenLangChoiceLayout();

		}
	};

	private OnItemClickListener onOcrlangListItemClick = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> adapter, View view,
				int position, long id) {
			// TODO Auto-generated method stub

			/*
			 * LangListItemView item = (LangListItemView) ocrlangListView
			 * .getChildAt(currentOCRLang); item.check.setChecked(false);
			 * 
			 * item = (LangListItemView) view; item.check.setChecked(true);
			 * ocrLangTextView.setText(item.lang.getText().toString());
			 * 
			 * currentOCRLang = position;
			 */
			ocrLangTextView.setText(ocrlangListView.getItemAtPosition(position)
					.toString());

		}
	};

	private OnItemClickListener onTranslangListItemClick = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> adapter, View view,
				int position, long id) {
			// TODO Auto-generated method stub
			/*
			 * LangListItemView item = (LangListItemView) translangListView
			 * .getChildAt(currentTransLang); item.check.setChecked(false);
			 * 
			 * item = (LangListItemView) view; item.check.setChecked(true);
			 * transLangTextView.setText(item.lang.getText().toString());
			 * 
			 * currentTransLang = position; // Log.i("Position",
			 * String.valueOf(position));
			 */
			transLangTextView.setText(translangListView.getItemAtPosition(
					position).toString());
		}
	};

	private OnClickListener onTranslatedTextViewClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			hiddenSearchChoice();
			hiddenShareChoice();
		}
	};

	private OnClickListener onCamerazoominButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Camera.Parameters params = preview.camera.getParameters();
			int zoom = params.getZoom();
			if (zoom < params.getMaxZoom())
				zoom++;
			params.setZoom(zoom);
			preview.camera.setParameters(params);
		}
	};

	private OnClickListener onCamerazoomoutButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Camera.Parameters params = preview.camera.getParameters();
			int zoom = params.getZoom();
			if (zoom > 0)
				zoom--;
			params.setZoom(zoom);
			preview.camera.setParameters(params);
		}
	};

	private OnClickListener onSwitchResultButtonClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			if (translatedTextviewShow) {
				hiddenTranslatedTextview();
				showOCRTextview();
				translatedTextviewShow = false;
			} else {
				showTranslatedTextview();
				hiddenOCRTextview();
				translatedTextviewShow = true;
			}
		}
	};
}